//// ProductController.java
//package com.xiaocikuai.smallchunks.controller.Product;
//
//
//import com.xiaocikuai.smallchunks.entity.Card.CardChunks;
//import com.xiaocikuai.smallchunks.entity.Product.Product;
//import com.xiaocikuai.smallchunks.entity.Product.ProInfoList;
//import com.xiaocikuai.smallchunks.entity.Product.Plan;
//import com.xiaocikuai.smallchunks.entity.Transaction.AddMale;
//import com.xiaocikuai.smallchunks.entity.Transaction.RedemptionCode;
//import com.xiaocikuai.smallchunks.entity.Transaction.YshopMaleList;
//import com.xiaocikuai.smallchunks.entity.Transaction.YshopRedemptionCode;
//import com.xiaocikuai.smallchunks.service.Product.ProductService;
//import com.xiaocikuai.smallchunks.service.Transaction.impl.RedemptionCodeServiceImpl;
//import com.xiaocikuai.smallchunks.utils.resultd.Resultd;
//import org.springframework.web.bind.annotation.*;
//import org.springframework.web.multipart.MultipartFile;
//
//import javax.annotation.Resource;
//import java.util.Date;
//import java.util.List;
////产品相关
//@RestController
//@RequestMapping("/api/product")
//@CrossOrigin
//public class ProductController {
//
//    @Resource
//    private ProductService productService;
//    @Resource
//    private RedemptionCodeServiceImpl redemptionCodeService;
//
//    // 获取产品列表
//    @PostMapping("/list")
//    public Resultd productList(@RequestHeader("Authorization") String token, @RequestBody Product product) {
//        try {
//            List<Product> productList = productService.getProductList(token, product);
//            if (productList!= null) {
//                return Resultd.ok().data("list", productList);
//            } else {
//                return Resultd.error();
//            }
//        } catch (Exception e) {
//            // 可以根据具体情况记录异常信息
//            return Resultd.error().data("info","获取产品列表时发生异常: " + e.getMessage());
//        }
//    }
//
//    // 获取产品详情
//    @PostMapping("/day")
//    public Resultd dayProduct(@RequestBody Plan plan) {
//        List<ProInfoList> dayProduct = productService.getDayProduct(plan);
//        if (dayProduct != null) {
//            return Resultd.ok().data("info", dayProduct);
//        } else {
//            return Resultd.error();
//        }
//    }
//
//    // 获取该日需学习的单词
//    @PostMapping("/plans")
//    public Resultd plans(@RequestHeader("Authorization") String token, @RequestBody Plan plans) {
//        List<CardChunks> plansList = productService.getPlans(token, plans);
//        if (plansList != null) {
//            return Resultd.ok().data("info", plansList);
//        } else {
//            return Resultd.error();
//        }
//    }
//
//    //每日需复习的单词
//    @PostMapping("/review")
//    public Resultd review(@RequestHeader("Authorization") String token) {
//        List<CardChunks> plansList = productService.getReviewWords(token);
//        if (plansList != null) {
//            return Resultd.ok().data("info", plansList);
//        } else {
//            return Resultd.error();
//        }
//    }
//
//    //获取产品详细信息
//    @PostMapping("/getInfo")
//    public Resultd getInfo(@RequestHeader("Authorization") String token, int pid) {
//        return Resultd.ok().data("info", productService.getInfo(pid));
//    }
//
//    //录入单词
//    @PostMapping("/enterWord")
//    public Resultd enterWord(@RequestHeader("Authorization") String token, int pid, List<Integer> cidS) {
//        return Resultd.ok().data("info", productService.enterWord(pid, cidS));
//    }
//
//    @PostMapping("/getShopInfoList")
//    public Resultd getShopInfoList(@RequestHeader("Authorization") String token, @RequestBody Product product) {
//        return Resultd.ok().data("info",  productService.getShopInfoList(product.getPid()));
//    }
//
//    @PostMapping("/getShopHashMap")
//    public Resultd getShopHashMap(@RequestHeader("Authorization") String token, @RequestBody YshopMaleList yshopMaleList) {
//        return Resultd.ok().data("info",  productService.getShopHashMap(yshopMaleList.getTid()));
//    }
//
//    @PostMapping("/getDetailImg")
//    public Resultd getDetailImg(@RequestHeader("Authorization") String token, @RequestBody YshopMaleList yshopMaleList) {
//        return Resultd.ok().data("info",  productService.getDetailImg(yshopMaleList.getTid()));
//    }
////    @PostMapping("/getProductInfo")
////    public Resultd getProductInfo(@RequestHeader("Authorization") String token, @RequestBody YshopMaleList yshopMaleList) {
////        return Resultd.ok().data("info",  productService.getProductInfo(yshopMaleList.getTid()));
////    }
//
//    //创建产品
//    @PostMapping("/addProduct")
//    public Resultd addProduct(@RequestHeader("Authorization") String token,@RequestBody Product product){
//        if (productService.addProduct(product)){
//            return Resultd.ok().data("info", "创建产品成功");
//        } else {
//            return Resultd.error().data("info", "创建产品失败");
//        }
//    }
//
////删除产品
//    @PostMapping("/deleteProductById")
//    public Resultd deleteProductById(@RequestHeader("Authorization") String token,@RequestBody Product product){
//        if (productService.deleteProductById(product)){
//            return Resultd.ok().data("info", "创建删除成功");
//        } else {
//            return Resultd.error().data("info", "创建删除失败");
//        }
//    }
//
////更新产品
//    @PostMapping("/updateProduct")
//    public Resultd updateProduct(@RequestHeader("Authorization") String token,@RequestBody Product product){
//        if (productService.updateProduct(product)){
//            return Resultd.ok().data("info", "创建更改成功");
//        } else {
//            return Resultd.error().data("info", "创建更改失败");
//        }
//    }
//
//
//    //获取产品列表
//    @PostMapping("/getProducts")
//    public Resultd getProducts(@RequestHeader("Authorization") String token,@RequestBody Product product){
//        List<Product> productList = productService.getProducts(product);
//        if (productList != null){
//            return Resultd.ok().data("info", productList);
//        } else {
//            return Resultd.error().data("info", "获取失败");
//        }
//    }
//
//    //获取商品列表
//    @PostMapping("/getMaleInfo")
//    public Resultd getMaleInfo(@RequestHeader("Authorization") String token ){
//        List<YshopMaleList> yshopMaleList = productService.getMaleInfo();
//        if (yshopMaleList != null){
//            return Resultd.ok().data("info", yshopMaleList);
//        } else {
//            return Resultd.error().data("info", "获取失败");
//        }
//    }
//
//
//    //获取产品价格
//    @PostMapping("/getPrice")
//    public Resultd getPrice(@RequestHeader("Authorization") String token,@RequestBody Product product ){
//        float price = productService.getPrice(product.getName());
//        if (price != 0){
//            return Resultd.ok().data("info", price);
//        } else {
//            return Resultd.error().data("info", "获取失败");
//        }
//    }
//
//    //上传商品图片
//    @PostMapping("/AddMale")
//    public Resultd AddMale(@RequestHeader("Authorization") String token, @RequestParam("file") List<MultipartFile> file){
//
//        String result = productService.AddMale(file);
//        if (!result.equals("[]")) {
//            return Resultd.ok().data("info",result);
//        } else {
//            return Resultd.error().data("info","添加成功");
//        }
//
//    }
//
//    //创建商品
//    @PostMapping("/insertMale")
//    public Resultd insertMale(@RequestHeader("Authorization") String token,@RequestBody YshopMaleList yshopMaleList){
//        if (productService.insertMale(yshopMaleList)) {
//            return Resultd.ok().data("info","添加成功");
//        } else {
//            return Resultd.error().data("info","添加失败");
//        }
//    }
//
//
//    //删除商品
//    @PostMapping("/deleteMaleById")
//    public Resultd deleteMaleById(@RequestHeader("Authorization") String token,@RequestBody YshopMaleList yshopMaleList){
//        if (productService.deleteMaleById(yshopMaleList)){
//            return Resultd.ok().data("info", "创建删除成功");
//        } else {
//            return Resultd.error().data("info", "创建删除失败");
//        }
//    }
//
//
//    //更新商品
//    @PostMapping("/updateMale")
//    public Resultd updateMale(@RequestHeader("Authorization") String token,@RequestBody YshopMaleList yshopMaleList){
//        if (productService.updateMale(yshopMaleList)){
//            return Resultd.ok().data("info", "创建更改成功");
//        } else {
//            return Resultd.error().data("info", "创建更改失败");
//        }
//    }
//
//
//
//
//
//    //查找商品
//    @PostMapping
//    public Resultd selectMaleById(@RequestHeader("Authorization") String token,@RequestBody YshopMaleList yshopMaleList){
//        if (productService.selectMaleById(yshopMaleList)) {
//            return Resultd.ok().data("info","添加成功");
//        } else {
//            return Resultd.error().data("info","添加失败");
//        }
//    }
//
//
////    @PostMapping("/getUniqueCode")
////    public Resultd getUniqueCode(){
////        String result = productService.getUniqueCode();
////        if (!result.isEmpty()) {
////            return Resultd.ok().data("info",result);
////        } else {
////            return Resultd.error().data("info","添加成功");
////        }
////
////    }
//
//
//    @PostMapping("/insertRedemptionCode")
//    public Resultd insertRedemptionCode(@RequestHeader("Authorization") String token,@RequestBody YshopRedemptionCode yshopRedemptionCode){
//        if (productService.insertRedemptionCode(yshopRedemptionCode)){
//            return Resultd.ok().data("info", "创建成功");
//        } else {
//            return Resultd.error().data("info", "创建失败");
//        }
//    }
//
//    @PostMapping("/addpid")
//    public Resultd addpid(@RequestHeader("Authorization") String token,@RequestBody Product product){
//        if (productService.binding(product.getClas(), product.getPid())){
//            return Resultd.ok().data("info", "绑定商品成功");
//        } else {
//            return Resultd.error().data("info", "该商品已绑定此产品");
//        }
//    }
//
//
//
//
//
//
//
//
//}

// ProductController.java
package com.xiaocikuai.smallchunks.controller.Product;

import com.xiaocikuai.smallchunks.entity.Advertise.ImgUni;
import com.xiaocikuai.smallchunks.entity.Card.CardChunks;
import com.xiaocikuai.smallchunks.entity.Product.Product;
import com.xiaocikuai.smallchunks.entity.Product.ProInfoList;
import com.xiaocikuai.smallchunks.entity.Product.Plan;
import com.xiaocikuai.smallchunks.entity.Transaction.*;
import com.xiaocikuai.smallchunks.service.Product.ProductService;
import com.xiaocikuai.smallchunks.service.Transaction.impl.MaleListServiceImpl;
import com.xiaocikuai.smallchunks.service.Transaction.impl.RedemptionCodeServiceImpl;
import com.xiaocikuai.smallchunks.utils.resultd.Resultd;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

// 产品相关
@Api(tags = "产品控制器")
@RestController
@RequestMapping("/api/product")
@CrossOrigin
public class ProductController {

    @Resource
    private ProductService productService;
    @Resource
    private MaleListServiceImpl maleListService;


    @ApiOperation(value = "获取产品列表")
    @PostMapping("/list")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "token", value = "授权令牌", required = true, dataType = "String", paramType = "header"),
            @ApiImplicitParam(name = "product", value = "产品信息", required = true, dataType = "Product", paramType = "body")
    })
    public Resultd productList(@RequestHeader("Authorization") String token, @RequestBody Product product) {
        try {
            List<Product> productList = productService.getProductList(token, product);
            if (productList!= null) {
                return Resultd.ok().data("list", productList);
            } else {
                return Resultd.error();
            }
        } catch (Exception e) {
            // 可以根据具体情况记录异常信息
            return Resultd.error().data("info","获取产品列表时发生异常: " + e.getMessage());
        }
    }

    @ApiOperation(value = "获取产品详情（按日）")
    @PostMapping("/day")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "plan", value = "计划信息", required = true, dataType = "Plan", paramType = "body")
    })
    public Resultd dayProduct(@RequestHeader("Authorization") String token,@RequestBody Plan plan) {
        List<ProInfoList> dayProduct = productService.getDayProduct(plan,token);
        if (dayProduct!= null) {
            return Resultd.ok().data("info", dayProduct);
        } else {
            return Resultd.error();
        }
    }

    @ApiOperation(value = "获取计划中的单词")
    @PostMapping("/plans")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "token", value = "授权令牌", required = true, dataType = "String", paramType = "header"),
            @ApiImplicitParam(name = "plans", value = "计划信息", required = true, dataType = "Plan", paramType = "body")
    })
    public Resultd plans(@RequestHeader("Authorization") String token, @RequestBody Plan plans) {
        List<CardChunks> plansList = productService.getPlans(token, plans);
        if (plansList!= null) {
            return Resultd.ok().data("info", plansList);
        } else {
            return Resultd.error();
        }
    }
    

    @ApiOperation(value = "获取产品详细信息")
    @PostMapping("/getInfo")
    public Resultd getInfo(@RequestHeader("Authorization") String token, @RequestBody  Product product) {
        return Resultd.ok().data("info", productService.getInfo(product.getPid(),token));
    }

    @ApiOperation(value = "录入单词")
    @PostMapping("/enterWord")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "token", value = "授权令牌", required = true, dataType = "String", paramType = "header"),
            @ApiImplicitParam(name = "pid", value = "产品 ID", required = true, dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "cidS", value = "单词 ID 列表", required = true, dataType = "List<Integer>", paramType = "body")
    })
    public Resultd enterWord(@RequestHeader("Authorization") String token, int pid, List<Integer> cidS) {
        return Resultd.ok().data("info", productService.enterWord(pid, cidS));
    }

    @ApiOperation(value = "获取店铺信息列表")
    @PostMapping("/getShopInfoList")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "token", value = "授权令牌", required = true, dataType = "String", paramType = "header"),
            @ApiImplicitParam(name = "product", value = "产品信息", required = true, dataType = "Product", paramType = "body")
    })
    public Resultd getShopInfoList(@RequestHeader("Authorization") String token, @RequestBody Product product) {
        return Resultd.ok().data("info",  productService.getShopInfoList(product.getPid()));
    }

    @ApiOperation(value = "获取店铺哈希表")
    @PostMapping("/getShopHashMap")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "token", value = "授权令牌", required = true, dataType = "String", paramType = "header"),
            @ApiImplicitParam(name = "yshopMaleList", value = "店铺男性列表信息", required = true, dataType = "YshopMaleList", paramType = "body")
    })
    public Resultd getShopHashMap(@RequestHeader("Authorization") String token, @RequestBody YshopMaleList yshopMaleList) {
        return Resultd.ok().data("info",  productService.getShopHashMap(yshopMaleList.getTid()));
    }

    @ApiOperation(value = "获取详情图片")
    @PostMapping("/getDetailImg")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "token", value = "授权令牌", required = true, dataType = "String", paramType = "header"),
            @ApiImplicitParam(name = "yshopMaleList", value = "店铺男性列表信息", required = true, dataType = "YshopMaleList", paramType = "body")
    })
    public Resultd getDetailImg(@RequestHeader("Authorization") String token, @RequestBody YshopMaleList yshopMaleList) {
        return Resultd.ok().data("info",  productService.getDetailImg(yshopMaleList.getTid()));
    }

    // 创建产品
    @ApiOperation(value = "创建产品")
    @PostMapping("/addProduct")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "token", value = "授权令牌", required = true, dataType = "String", paramType = "header"),
            @ApiImplicitParam(name = "product", value = "产品信息", required = true, dataType = "Product", paramType = "body")
    })
    public Resultd addProduct(@RequestHeader("Authorization") String token,@RequestBody Product product){
        if (productService.addProduct(product)){
            return Resultd.ok().data("info", "创建产品成功");
        } else {
            return Resultd.error().data("info", "创建产品失败");
        }
    }

    // 删除产品
    @ApiOperation(value = "删除产品")
    @PostMapping("/deleteProductById")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "token", value = "授权令牌", required = true, dataType = "String", paramType = "header"),
            @ApiImplicitParam(name = "product", value = "产品信息", required = true, dataType = "Product", paramType = "body")
    })
    public Resultd deleteProductById(@RequestHeader("Authorization") String token,@RequestBody Product product){
        if (productService.deleteProductById(product)){
            return Resultd.ok().data("info", "创建删除成功");
        } else {
            return Resultd.error().data("info", "创建删除失败");
        }
    }

    // 更新产品
    @ApiOperation(value = "更新产品")
    @PostMapping("/updateProduct")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "token", value = "授权令牌", required = true, dataType = "String", paramType = "header"),
            @ApiImplicitParam(name = "product", value = "产品信息", required = true, dataType = "Product", paramType = "body")
    })
    public Resultd updateProduct(@RequestHeader("Authorization") String token,@RequestBody Product product){
        if (productService.updateProduct(product)){
            return Resultd.ok().data("info", "创建更改成功");
        } else {
            return Resultd.error().data("info", "创建更改失败");
        }
    }

    // 获取产品列表
    @ApiOperation(value = "获取产品列表")
    @PostMapping("/getProducts")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "token", value = "授权令牌", required = true, dataType = "String", paramType = "header"),
            @ApiImplicitParam(name = "product", value = "产品信息", required = true, dataType = "Product", paramType = "body")
    })
    public Resultd getProducts(@RequestHeader("Authorization") String token,@RequestBody Product product){
        List<Product> productList = productService.getProducts(product);
        if (productList!= null){
            return Resultd.ok().data("info", productList);
        } else {
            return Resultd.error().data("info", "获取失败");
        }
    }

    // 获取商品列表
    @ApiOperation(value = "获取商品列表")
    @PostMapping("/getMaleInfo")
    @ApiImplicitParam(name = "token", value = "授权令牌", required = true, dataType = "String", paramType = "header")
    public Resultd getMaleInfo(@RequestHeader("Authorization") String token ){
        List<YshopMaleList> yshopMaleList = productService.getMaleInfo();
        if (yshopMaleList!= null){
            return Resultd.ok().data("info", yshopMaleList);
        } else {
            return Resultd.error().data("info", "获取失败");
        }
    }

    // 获取商品价格
    @ApiOperation(value = "获取商品价格")
    @PostMapping("/getPrice")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "token", value = "授权令牌", required = true, dataType = "String", paramType = "header"),
            @ApiImplicitParam(name = "product", value = "产品信息", required = true, dataType = "Product", paramType = "body")
    })
    public Resultd getPrice(@RequestHeader("Authorization") String token,@RequestBody Product product ){
        float price = productService.getPrice(product.getName());
        if (price!= 0){
            return Resultd.ok().data("info", price);
        } else {
            return Resultd.error().data("info", "获取失败");
        }
    }

    // 上传商品图片
    @ApiOperation(value = "上传商品图片")
    @PostMapping("/AddMale")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "token", value = "授权令牌", required = true, dataType = "String", paramType = "header"),
            @ApiImplicitParam(name = "file", value = "商品图片文件列表", required = true, dataType = "List<MultipartFile>", paramType = "form")
    })
    public Resultd AddMale(@RequestHeader("Authorization") String token, @RequestParam("file") List<MultipartFile> file) {

        String result = productService.AddMale(file);
        if (!result.equals("[]")) {
            return Resultd.ok().data("info", result);
        } else {
            return Resultd.error().data("info", "添加失败");
        }
    }
    // 创建商品
    @ApiOperation(value = "创建商品")
    @PostMapping("/insertMale")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "token", value = "授权令牌", required = true, dataType = "String", paramType = "header"),
            @ApiImplicitParam(name = "yshopMaleList", value = "商品信息", required = true, dataType = "YshopMaleList", paramType = "body")
    })
    public Resultd insertMale(@RequestHeader("Authorization") String token,@RequestBody YshopMaleList yshopMaleList){
        if (productService.insertMale(yshopMaleList)) {
            return Resultd.ok().data("info","添加成功");
        } else {
            return Resultd.error().data("info","添加失败");
        }
    }

    // 删除商品
    @ApiOperation(value = "删除商品")
    @PostMapping("/deleteMaleById")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "token", value = "授权令牌", required = true, dataType = "String", paramType = "header"),
            @ApiImplicitParam(name = "yshopMaleList", value = "商品信息", required = true, dataType = "YshopMaleList", paramType = "body")
    })
    public Resultd deleteMaleById(@RequestHeader("Authorization") String token,@RequestBody YshopMaleList yshopMaleList){
        if (productService.deleteMaleById(yshopMaleList)){
            return Resultd.ok().data("info", "创建删除成功");
        } else {
            return Resultd.error().data("info", "创建删除失败");
        }
    }

    // 更新商品
    @ApiOperation(value = "更新商品")
    @PostMapping("/updateMale")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "token", value = "授权令牌", required = true, dataType = "String", paramType = "header"),
            @ApiImplicitParam(name = "yshopMaleList", value = "商品信息", required = true, dataType = "YshopMaleList", paramType = "body")
    })
    public Resultd updateMale(@RequestHeader("Authorization") String token,@RequestBody MaleList maleList){
        if (productService.updateMale(maleList)){
            return Resultd.ok().data("info", "创建更改成功");
        } else {
            return Resultd.error().data("info", "创建更改失败");
        }
    }

    // 查找商品
    @ApiOperation(value = "查找商品")
    @PostMapping("/selectMaleById")

    @ApiImplicitParams({
            @ApiImplicitParam(name = "token", value = "授权令牌", required = true, dataType = "String", paramType = "header"),
            @ApiImplicitParam(name = "yshopMaleList", value = "商品信息", required = true, dataType = "YshopMaleList", paramType = "body")
    })
    public Resultd selectMaleById(@RequestHeader("Authorization") String token, @RequestBody MaleList maleList){
        MaleList male = maleListService.selectMaleById(maleList);
        if (male != null) {
            return Resultd.ok().data("info",male);
        } else {
            return Resultd.error().data("info","添加失败");
        }
    }

    @ApiOperation(value = "插入兑换码")
    @PostMapping("/insertRedemptionCode")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "token", value = "授权令牌", required = true, dataType = "String", paramType = "header"),
            @ApiImplicitParam(name = "yshopRedemptionCode", value = "兑换码信息", required = true, dataType = "YshopRedemptionCode", paramType = "body")
    })
    public Resultd insertRedemptionCode(@RequestHeader("Authorization") String token,@RequestBody YshopRedemptionCode yshopRedemptionCode){
        if (productService.insertRedemptionCode(yshopRedemptionCode)){
            return Resultd.ok().data("info", "创建成功");
        } else {
            return Resultd.error().data("info", "创建失败");
        }
    }



    @ApiOperation(value = "绑定产品")
    @PostMapping("/addpid")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "token", value = "授权令牌", required = true, dataType = "String", paramType = "header"),
            @ApiImplicitParam(name = "product", value = "产品信息", required = true, dataType = "Product", paramType = "body")
    })
    public Resultd addpid(@RequestHeader("Authorization") String token,@RequestBody Product product){
        if (productService.binding(product.getClas(), product.getPid())){
            return Resultd.ok().data("info", "绑定商品成功");
        } else {
            return Resultd.error().data("info", "该商品已绑定此产品");
        }
    }

    @PostMapping("/getUni")
    public Resultd getUni(@RequestBody Product product){
        String icon = productService.getUni(product.getName());
        if (icon != null){
            return Resultd.ok().data("info", icon);
        } else {
            return Resultd.error().data("info", "加载图标失败");
        }
    }

    //获取主页轮播图
    @PostMapping("/getHomeUni")
    public Resultd getHomeUni(@RequestBody ImgUni imgUni){

        List<ImgUni> icon = productService.getHomeUni(imgUni.getType());
        if (icon != null){
            return Resultd.ok().data("info", icon);
        } else {
            return Resultd.error().data("info", "加载图片失败");
        }
    }

    // 上传产品图片
    @ApiOperation(value = "上传产品图片")
    @PostMapping("/AddImg")
    public Resultd AddProduct(@RequestHeader("Authorization") String token, @RequestParam("file") MultipartFile file,@RequestBody  Product product){


        if ( productService.updateAvatar(file,token,product.getPid())) {
            return Resultd.ok().data("info","添加成功");
        } else {
            return Resultd.error().data("info","添加失败");
        }

    }

    @ApiOperation(value = "获取产品信息")
    @PostMapping("/getProductInfo")
    public Resultd getProductInfo(@RequestHeader("Authorization") String token, @RequestBody  Product product){
        List<String> result = productService.getProductInfo(product.getPid(),token);
        if (result != null ) {
            return Resultd.ok().data("info",result);
        } else {
            return Resultd.error().data("info","添加失败");
        }
    }



}
